package cn.shop.dys.activity;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import cn.shop.dys.R;
import cn.shop.lib_common.CommonUtil;

public class LogisticsActivity extends AppCompatActivity {
    @ViewInject(R.id.iv_common_back)
    private ImageView mImgDetailsBack;
    @ViewInject(R.id.tv_common_index_titile)
    private TextView mTvDetailsIndexTitle;
    @ViewInject(R.id.iv_common_settings)
    private ImageView mImgDetailsSettings;
    private PopupWindow mPopupWindow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics);
        ViewUtils.inject(this);
        mTvDetailsIndexTitle.setText("物流查询");
        initEvent();
    }
    private void initEvent() {
        mImgDetailsBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mImgDetailsSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initPopupWindow(v);
            }
        });
    }
    private void initPopupWindow (View view){
        View pwView = View.inflate(this, R.layout.view_popupwindow, null);
        View pwTop=pwView.findViewById(R.id.ll_pw_top);
        View pwBottom=pwView.findViewById(R.id.ll_pw_bottom);
        mPopupWindow = new PopupWindow(pwView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        mPopupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
        int[] location = new int[2];
        view.getLocationInWindow(location);
        mPopupWindow.showAsDropDown(view, (int) -CommonUtil.dpToPx(this, 100), (int) -CommonUtil.dpToPx(this, 0));
        pwTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LogisticsActivity.this, MessageActivity.class);
                startActivity(intent);
                mPopupWindow.dismiss();
            }
        });
        pwBottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LogisticsActivity.this, MainActivity2.class);
                startActivity(intent);
                mPopupWindow.dismiss();
            }
        });
    }
}
